package com.sumainfor.pc.epc.service.impl;
import com.sumainfor.common.Constants;
import com.sumainfor.common.config.RedisUtils;
import com.sumainfor.common.util.*;
import com.sumainfor.common.utlis.ComUtils;
import com.sumainfor.common.utlis.HtmlUtil;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.epc.dao.*;
import com.sumainfor.pc.epc.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.epc.feign.Zfeign.ZzuulFeign;
import com.sumainfor.pc.epc.service.HoHpiService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.awt.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

@Service
public class HoHpiServiceImpl implements HoHpiService {
    private ReentrantLock lock = new ReentrantLock(false);//
    Logger log = LoggerFactory.getLogger(HoHpiServiceImpl.class);// 日志
    @Autowired
    private HoHpiMapper hoHpiMapper;
    @Autowired
    private HoHpbMapper hoHpbMapper;
    @Autowired
    private UtilsMapper utilsMapper;
    @Autowired
    private HoHiaMapper hoHiaMapper;
    @Autowired
    private HoHikMapper hoHikMapper;
    @Autowired
    private HoDecoratePiMapper hoDecoratePiMapper;
    @Autowired
    private ZpcMktFeign zpcMktFeign;
    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    ZzuulFeign ZzuulFeign;
    /**
     * 修改房源配置列表
     * @param params
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public JsonResult updateHoHpi(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        lock.lock();
        try{
            try {
                if (params.get("houConList")==null){
                    return result.putFailed("参数不正确");
                }
                //组装参数
                Map<String,Object> map=new HashMap<String,Object>();
                map.put("by", ContextUtils.getUserId());//操作人
                map.put("SysUserId",ContextUtils.getUserId());//验房人时间
                map.put("term", "4");// 更新端 Update端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                map.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonUpdateParms(map);
                map.put("InspectTime",params.get("updtm"));//验房时间
                List<Map<String,Object>> deList=(List<Map<String,Object>>)params.get("houConList");
                int num=0;
                for (Map<String,Object> deMap:deList){
                    deMap.putAll(map);
                    num=num+hoHpiMapper.updateHoHpi(deMap);
                }
                if (num==deList.size()){
                    result.putSuccess("操作成功");
                }else{
                    result.putFailed("服务器繁忙");
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                }
            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        }
        finally {
            lock.unlock();
        }
        return result;
    }
    /**
     *查询某个房源的配置详表OR网络和电视
     */
    @Override
    public JsonResult getHoHpiIfWiFiList(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        if (params.get("HouId")==null){
            return result.putFailed("参数不正确");
        }
        List<Map<String,Object>> list=hoHpiMapper.getHoHpiIfWiFiList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *查询某套房源的 各个审核状态的数量
     */
    @Override
    public JsonResult getHoHpiStateCount(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        if (params.get("HouId")==null){
            return result.putFailed("参数不正确");
        }
        Map<String,Object> map=hoHpiMapper.getHoHpiStateCount(params);
        if (map!=null){
            result.put(map);
        }else{
            result.putFailed("参数不正确");
        }
        return result;
    }
    /**
     * 修改房源配置列表
     * @param params
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public JsonResult updateHoHpiHpb(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        lock.lock();
        try{
            try {
                if (params.get("houList")==null || params.get("decorList")==null || params.get("netWorkList")==null
                || params.get("PlansId")==null || params.get("PlanId")==null || params.get("Operator")==null
                || params.get("CheckNoticeTime")==null || params.get("Bcount")==null || params.get("Acount")==null){
                    return result.putFailed("参数不正确");
                }
                //一个装修计划中未确认的其他费用数量 + 个装修计划中未完成装修的房源数量
                BigDecimal sumCount=new BigDecimal(params.get("Acount").toString()).add(new BigDecimal(params.get("Bcount").toString()));
                String userId=ContextUtils.getUserId();//当前登录的id
                //验房记录
                String UUID="";
                int keepNum=0;//保存验房不同过的数字
                int AccepNum=0;//保存房源配置验收中的数量
                Map<String,Object>uuid=utilsMapper.getUUID(new HashMap<String,Object>(){{
                    put("uuid", "AssId");
                    put("database", Constants.DATA_SOURCE_TCEPC);
                    put("surface", "tcepc_housing_inspe_assistant");
                }});
                if(uuid!=null){
                    int number=Integer.valueOf(uuid.get("uuid").toString());
                    UUID= ComUtils.getLocalTrmSeqNum("thia",number);
                }else{
                    UUID=ComUtils.getLocalTrmSeqNum("thia",0);
                }
                Map<String,Object> map2=new HashMap<String,Object>();
                map2.put("AssId",UUID);//工程助理-验房操作记录编号
                map2.put("by", userId);//操作人
                map2.put("Feedback",userId);//管家操作人
                map2.put("term", "4");// 更新端 Update端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                map2.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonInsertParms(map2);
                map2.put("PlanId",params.get("PlanId"));//装修计划编号
                map2.put("PlansId",params.get("PlansId"));//装修计划详表编号
                map2.put("Operator",params.get("Operator"));//工程助理编号
                map2.put("OperatorTime",map2.get("instm"));//工程助理操作时间
                map2.put("NoticeTime",params.get("CheckNoticeTime"));//通知管家时间
                map2.put("FeedbackTime",map2.get("instm"));//管家反馈时间
//
                //组装验房参数
                Map<String,Object> map=new HashMap<String,Object>();
                map.put("by", userId);//操作人
                map.put("SysUserId",userId);//验房人时间
                map.put("term", "4");// 更新端 Update端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                map.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonUpdateParms(map);
                map.put("InspectTime",map.get("updtm"));//验房时间
                System.out.println("验房通过的对象:"+map);
                //土建验房项
                List<Map<String,Object>> deList1=(List<Map<String,Object>>)params.get("decorList");
                int num1=0;
                for (Map<String,Object> deMap:deList1){
                    //如果有不通过就新增一条
                    //Status 验房单状态    0无状态  1.验收中  2.不通过   3通过
                    if (deMap.get("Status").toString().equals("2")){
                        map2.put("KeepId", UUID+keepNum);//uuid
                        map2.put("PalHouId",deMap.get("HouConId"));//房源配置编号
                        map2.put("HouConIds",deMap.get("HouConIds"));//房源配置子编号
                        map2.put("RefusalTime",map2.get("instm"));//驳回时间
                        map2.put("Remarks",deMap.get("Remark"));//驳回备注
                        map2.put("Annex",deMap.get("Annex"));//驳回图片
                        map2.put("Status",1);//驳回状态    0.通过    1.未通过
                        map2.put("Operator",userId);//管家编号
                        hoHikMapper.addHoHik(map2);
                        keepNum++;
                    }else if (deMap.get("Status").toString().equals("0") || deMap.get("Status").toString().equals("1")){
                        AccepNum++;
                    }
                    deMap.putAll(map);
                    num1=num1+hoHpbMapper.updateHoHpb(deMap);
                }
                //各个房间
                List<Map<String,Object>> deList2=(List<Map<String,Object>>)params.get("houList");
                int num2=0;
                int num4=0;
                for (Map<String,Object> deMap:deList2){
                    List<Map<String,Object>> conList=(List<Map<String,Object>>)deMap.get("conList");
                    num4=num4+conList.size();
                    System.out.println("conList="+conList);
                    for (Map<String,Object> deMap2:conList) {
                        //InspectState 验房单状态    0无状态  1.验收中  2.不通过   3通过
                        if (deMap2.get("InspectState").toString().equals("2")){
                            map2.put("KeepId", UUID+keepNum);//uuid
                            map2.put("PalHouId",deMap2.get("HouCon"));//房源配置编号
                            map2.put("HouConIds",deMap2.get("HouConIds"));//房源配置子编号
                            map2.put("RefusalTime",map2.get("instm"));//驳回时间
                            map2.put("Remarks",deMap2.get("InspectNotes"));//驳回备注
                            map2.put("Annex",deMap2.get("Annex"));//驳回备注
                            map2.put("Status",1);//驳回状态    0.通过    1.未通过
                            map2.put("Operator",userId);//管家编号
                            hoHikMapper.addHoHik(map2);
                            keepNum++;
                        }else if (deMap2.get("InspectState").toString().equals("0") || deMap2.get("InspectState").toString().equals("1")){
                            AccepNum++;
                        }

                        deMap2.putAll(map);
                        System.out.println("各个房间:"+deMap2);
                        num2 = num2 + hoHpiMapper.updateHoHpi(deMap2);
                    }
                }
                //网络
                List<Map<String,Object>> deList3=(List<Map<String,Object>>)params.get("netWorkList");
                int num3=0;
                for (Map<String,Object> deMap:deList3){
                    if (deMap.get("InspectState").toString().equals("2")) {
                        map2.put("KeepId", UUID+keepNum);//uuid
                        map2.put("PalHouId",deMap.get("HouCon"));//房源配置编号
                        map2.put("HouConIds",deMap.get("HouConIds"));//房源配置子编号
                        map2.put("RefusalTime", map2.get("instm"));//驳回时间
                        map2.put("Remarks", deMap.get("InspectNotes"));//驳回备注
                        map2.put("Annex", deMap.get("Annex"));//驳回图片
                        map2.put("Status", 1);//驳回状态    0.通过    1.未通过
                        map2.put("Operator",userId);//管家编号
                        hoHikMapper.addHoHik(map2);
                        keepNum++;
                    }else if (deMap.get("InspectState").toString().equals("0") || deMap.get("InspectState").toString().equals("1")){
                        AccepNum++;
                    }
                    deMap.putAll(map);
                    num3=num3+hoHpiMapper.updateHoHpi(deMap);
                }

                //反馈状态    0.无状态    0.被驳回   1.验房成功
                if (keepNum==0){////是验房通过  keepNum=0;//保存验房不同过的数字
                    System.out.println("验房通过");
                    map.put("FitmentState","2");//装修阶段状态         1装修中   2装修完成
                    map.put("CheckState","2");//装修计划验房阶段状态  1.装修中   2.验房完成
                    map.put("CheckStatus","3");//0.无状态   1.待验房（通知之后）  2.验房未通过  3.验房通过
                    map.put("IfCheckState","0");//管家验房是否异常 0正常 1异常
                    map2.put("Status","1");// 新增工程助理验房记录参数  0 不通过 1通过

                    //新的特价房源审核通知
                    CustomMap data = CustomMap.create("MeType", 4)
                            .put("Title", "新的需定价房源")
                            .put("Content", HtmlUtil.stringToHTML(String.format("注意！你有新的房源（%s）需要定价！；",params.get("HouId")), params.get("HouId").toString(), Color.blue))
                            .put("by", userId)
                            .put("IfJump", 1)
                            .put("Neturl", "sys-ServiceManager/serpricing")
                            .put("term", 3);
                    ZzuulFeign.AddMessage(data);

                }else if (keepNum>0){
                    System.out.println("验房不通过");
                    map.put("CheckStatus","2");//0.无状态   1.待验房（通知之后）  2.验房未通过  3.验房通过
                    map.put("IfCheckState","1");//管家验房是否异常 0正常 1异常
                    map2.put("Status","0");// 新增工程助理验房记录参数  0 不通过 1通过
                }
                System.out.println("AccepNum:"+AccepNum);
                System.out.println("keepNum:"+keepNum);
                if (!(AccepNum>0 && keepNum==0)){//排除 全部房源配置都是验收中，没有一个通过或者不通过
                    //新增工程助理验房记录
                    hoHiaMapper.addHoHia(map2);
                    map.put("PlansId",params.get("PlansId"));
                    map.put("CheckRealityTime",map.get("updtm"));//管家验房阶段实际完成时间
                    //修改装修计划详表
                    hoDecoratePiMapper.updateHdpi(map);
                    System.out.println("AccepNum:"+AccepNum);
                    System.out.println("num1="+num1);
                    System.out.println("deList1.size()="+deList1.size());
                    System.out.println("num2="+num2);
                    System.out.println("num4="+num4);
                    System.out.println("num3="+num3);
                    System.out.println("deList3.size()="+deList3.size());
                    //到市场部新增房源配置
                    if (num1==deList1.size() && num2==num4 && num3==deList3.size()){
                        JsonResult marketResult=new JsonResult();
                        //验房全部通过以后去市场部新增房源
                        if (keepNum==0 && AccepNum==0) {
                            marketResult = zpcMktFeign.addHouCon(params);
                            if (marketResult.get("errorCode").toString().equals("0")){
                                //如果未验房通过的数量和未2确认其他费用的数量总和为零的话修改整个装修计划为通过
                                if (sumCount.compareTo(new BigDecimal("1")) == 0){
                                    Map<String,Object> hoDecorate=new HashMap<String, Object>();
                                    hoDecorate.put("PlanState","4");//装修计划状态     1.审核中  2被驳回  3.装修中   \n4.已完成
                                    hoDecorate.put("by", userId);//操作人
                                    hoDecorate.put("PlanId",params.get("PlanId"));//当前装修计划的编号
                                    hoDecorate.put("term", "4");// 更新端 Update端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                                    hoDecorate.put("fnc",
                                            this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                                    ParamsCommon.commonUpdateParms(hoDecorate);
                                    Integer count=hoDecoratePiMapper.updateHoDecorate(hoDecorate);
                                    if(count!=null && count==1){
                                        result.putSuccess("操作成功");
                                    }else {
                                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                        result.putFailed("服务器繁忙");
                                    }
                                }else{
                                    result.putSuccess("操作成功");
                                }

                            }else{
                                result.putFailed("服务器繁忙");
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            }
                        }
                        result.putSuccess("操作成功");
                    }else{
                        result.putFailed("服务器繁忙");
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                }else{
                    result.putSuccess("操作成功");
                }

            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        }
        finally {
            lock.unlock();
        }
        return result;
    }
    /**
     * 租客端 充值智能设备查询智能设备的设备编号
     */
    @Override
    public JsonResult getHoRdInteDeviceConList(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        //查询房间的智能电表（一个房间只能有一个智能电表）
        List<Map<String,Object>> hpiList=hoHpiMapper.getHoRdInteDeviceConList(params);
        Map<String,Object> hpiMap=new HashMap<String,Object>();
        if (hpiList.size()>1){
            return result.putFailed("房间配置异常，房间的智能电表不唯一");
        }else{
            hpiMap=hpiList.get(0);
        }
        if (hpiMap!=null){
            // 0.蜂电   1.大华   2.科技侠   3.果加
            if (hpiMap.get("Intelligent").toString().equals("0")){
                String InteDeviceBeeToken=redisUtils.get("InteDeviceBeeToken");
                //如果获取不到就重新登录
                if (InteDeviceBeeToken==null) {
                    Map<String, Object> tokenMap = new HashMap<String, Object>();
                    params.put("version","0116010101");//版本号 默认 0116010101
                    params.put("appid", InteDeviceBeeConfig.APP_ID);
                    tokenMap= InteDeviceBeeUtil.userLogin(InteDeviceBeeConfig.USERID, InteDeviceBeeConfig.PASS,params);
                    if (tokenMap.get("Code").toString().equals("0")) {
                        InteDeviceBeeToken = tokenMap.get("Expand").toString();
                        //token存到redis中 有效时长一个小时
                        redisUtils.set("InteDeviceBeeToken", InteDeviceBeeToken,3600);
                    } else {
                        return result.putFailed("token获取失败");
                    }
                }

                //获取单个单表（为了获取到智能设备的设备UUID）
                Map<String,Object> pcodeParams=new HashMap<String, Object>();
                pcodeParams.put("uid",InteDeviceBeeConfig.UID);
                pcodeParams.put("token",InteDeviceBeeToken);
                Map<String,Object> inteBeeMap=InteDeviceBeeUtil.deviceAmmeter(hpiMap.get("Identifier").toString(),pcodeParams);
                if (inteBeeMap.get("Code").toString().equals("0")) {
                    List<Map<String, Object>> dataList = (List<Map<String, Object>>) inteBeeMap.get("Data");
                    hpiMap.put("Uuid", dataList.get(0).get("Uuid"));
                }else{
                    return result.put("蜂电服务器异常");
                }
            }
            result.put(hpiMap);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *租客端统计智能设备余额 查询房间的智能设备编号列表
     */
    @Override
    public JsonResult getHoRdCensusInteDeviceList(Map<String, Object> params) {
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=hoHpiMapper.getHoRdCensusInteDeviceList(params);
        //保存蜂电的智能设备编号列表
      /*  List<String> beeIdList=new ArrayList<String>();
        for(Map<String,Object> map :list){
            if(map.get("Intelligent")!=null){
                beeIdList.add(map.get("Identifier").toString());
            }
        }*/
        //如果蜂电智能电表的设备编号集合不为空就去查询蜂电的智能设备编号的UUID
       /* if (beeIdList.size()>0){
            String InteDeviceBeeToken=redisUtils.get("InteDeviceBeeToken");
            //如果获取不到就重新登录
            if (InteDeviceBeeToken==null) {
                Map<String, Object> tokenMap = new HashMap<String, Object>();
                params.put("version","0116010101");//版本号 默认 0116010101
                params.put("appid", InteDeviceBeeConfig.APP_ID);
                tokenMap= InteDeviceBeeUtil.userLogin(InteDeviceBeeConfig.USERID, InteDeviceBeeConfig.PASS,params);
                if (tokenMap.get("Code").toString().equals("0")) {
                    InteDeviceBeeToken = tokenMap.get("Expand").toString();
                    //token存到redis中 有效时长一个小时
                    redisUtils.set("InteDeviceBeeToken", InteDeviceBeeToken,3600);
                } else {
                    return result.putFailed("token获取失败");
                }
            }
            //查询各个房间的智能电表的UUID
            //查询智能电表的UUID集合
            Map<String,Object> pcodeParams=new HashMap<String, Object>();
            pcodeParams.put("uid",InteDeviceBeeConfig.UID);
            pcodeParams.put("token",InteDeviceBeeToken);
            Map<String,Object> pcodeMap=InteDeviceBeeUtil.deviceAmmeterPcode(beeIdList,pcodeParams);
            List<Map<String,Object>> pcodeList=(List<Map<String,Object>>)pcodeMap.get("Data");
            List<String> beeUuidList=new ArrayList<String>();//保存智能设备的UUID
            for (Map<String,Object> map1: list){
                if (map1.get("Identifier")!=null){
                    for (Map<String,Object> map2:pcodeList){
                        if (map2.get("Uuid")!=null){
                            if (map1.get("Identifier").toString().equals(map2.get("Uuid").toString())){
                                map1.put("Uuid",map2.get("Uuid"));
                            }
                        }
                    }
                }
            }
        }*/
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }
    /**
     *智能设备充值 查询租客所租的房子智能设备余额的和
     */
    public JsonResult getRdCensusHouConInfo(Map<String,Object> params){
        JsonResult result=new JsonResult();
        if (params.get("InteDeviceList")==null || params.get("HouConId")==null
                || params.get("EleFee")==null ){
            return result.putFailed("参数不正确");
        }
        Map<String,Object> resultMap=new HashMap<String,Object>();
        BigDecimal eleMoneySum=new BigDecimal("0");//智能电表总余额
        BigDecimal eleMoneyBee=new BigDecimal("0");//蜂电智能电表余额
        BigDecimal eleMoneyDaHua=new BigDecimal("0");//大华智能电表余额
        BigDecimal EleFee=new BigDecimal(params.get("EleFee").toString());//电表的收费标准
        Map<String,Object> gmioMap=null;//当前房间的电表信息对象
        //当前房源的电表信息
        List<Map<String,Object>> inteDeviceList=(List<Map<String,Object>>)params.get("InteDeviceList");
        for(Map<String,Object> inteMap: inteDeviceList){
            if (inteMap.get("HouConId")!=null && inteMap.get("HouConId").equals(params.get("HouConId").toString())){
                gmioMap=inteMap;
            }
        }
        if(gmioMap!=null) {
            //Intelligent 智能设备供应商     0.蜂电   1.大华   2.科技侠   3.果加
            if (gmioMap.get("Intelligent").toString().equals("0")) {
                String InteDeviceBeeToken=redisUtils.get("InteDeviceBeeToken");
                //如果获取不到就重新登录
                if (InteDeviceBeeToken==null) {
                    Map<String, Object> tokenMap = new HashMap<String, Object>();
                    tokenMap.put("version","0116010101");//版本号 默认 0116010101
                    tokenMap.put("appid",InteDeviceBeeConfig.APP_ID);
                    tokenMap=InteDeviceBeeUtil.userLogin(InteDeviceBeeConfig.USERID, InteDeviceBeeConfig.PASS,tokenMap);
                    if (tokenMap.get("Code").toString().equals("0")) {
                        InteDeviceBeeToken = tokenMap.get("Expand").toString();
                        //token存到redis中 有效时长一个小时
                        redisUtils.set("InteDeviceBeeToken", InteDeviceBeeToken,3600);
                    } else {
                        return result.putFailed("token获取失败");
                    }
                }
                //蜂电请求必填的head参数
                Map<String,Object> headMap=new HashMap<String, Object>();
                headMap.put("uid",InteDeviceBeeConfig.UID);
                headMap.put("token",InteDeviceBeeToken);
                //查询单个电表的数据
                Map<String,Object> InteResultMap=InteDeviceBeeUtil.deviceAmmeter(gmioMap.get("Uuid").toString(),headMap);
                System.out.println("InteDataMap:"+InteResultMap);
                System.out.println("InteDataMap.get(\"Code\").toString().equals(\"0\"):"+InteResultMap.get("Code").toString().equals("0"));
                System.out.println("InteDataMap.get(\"Expand\"):"+InteResultMap.get("Expand"));
                if (InteResultMap.get("Code").toString().equals("0")) {// 0蜂电接口返回正常
                    List<Map<String,Object>> InteDataList=(List<Map<String,Object>>)InteResultMap.get("Data");
                    for(Map<String,Object> InteDataMap:InteDataList){
                        if (InteDataMap.get("Expand")!=null){
                            Map<String,Object>aMap=(Map<String,Object>)InteDataMap.get("Expand");
                            //蜂电余额+=电表剩余可用电量*收费标准
                            eleMoneyBee=eleMoneyBee.add(new BigDecimal(aMap.get("surplus").toString()).multiply(EleFee));
                            System.out.println("电表读数："+aMap.get("surplus").toString());
                            System.out.println("电费收费标准："+EleFee);
                        }
                    }
                }
            }else if(gmioMap.get("Intelligent").toString().equals("1")){//大华智能电表
                String InteDaHuaToken=redisUtils.get("InteDaHuaToken");
                //如果获取不到就重新登录
                if (InteDaHuaToken==null){
                    /*获取token*/
                    Map<String,Object> DaParams=new HashMap<String, Object>();
                    DaParams.put("pw",InteDeviceDaHuaConfig.PW);
                    DaParams.put("userName",InteDeviceDaHuaConfig.USERNAME);
                    DaParams=InteDeviceDaHuaUtil.getToken(DaParams);
                    if (DaParams.get("code")!=null && DaParams .get("code").toString().equals("1")){//1 状态码 请求成功
                        InteDaHuaToken=DaParams.get("data").toString();
                        //token有效期2个小时，所有接口Code=0 ，token失效 需要重新获取
                        redisUtils.set("InteDaHuaToken",InteDaHuaToken,3600*2);
                    }else{
                        return result.putFailed("token获取失败");
                    }
                }
                //保存智能设备编号
                String [] InteArr =new String[inteDeviceList.size()];
                for(int i=0;i<inteDeviceList.size();i++){
                    Map<String,Object> map=inteDeviceList.get(i);
                    if (map.get("Identifier")!=null && !map.get("Identifier").toString().equals("")){
                        InteArr[i]=(map.get("Identifier").toString());
                    }
                }
                //逗号隔开的智能设备字符串
                String level1= StringUtils.join(InteArr, ",");
                Map<String,Object> getParams=new HashMap<String,Object>();
                getParams.put("token",InteDaHuaToken);//访问token
                getParams.put("level1",level1);//逗号隔开的字符串
                //查询智能设备的电表读数
                getParams=InteDeviceDaHuaUtil.getAllRemainByLevel1(getParams);
                if (getParams.get("code")!=null && getParams .get("code").toString().equals("1")) {//0 状态码 请求成功
                    BigDecimal price=new BigDecimal("0");//保存大华的电表单价
                    BigDecimal sumMoney=new BigDecimal("0");//保存大华的电表余额
                    //电表数组
                    List<Map<String,Object>> dataList=(List<Map<String,Object>>)getParams.get("data");
                    System.out.println("dataList:"+dataList);
                    System.out.println("InteDeviceBeeList:"+inteDeviceList);
                    for (Map<String,Object> map2:dataList){
                        if (map2.get("price")!=null){
                            price=new BigDecimal(map2.get("price").toString());
                        }
                        if (map2.get("data")!=null){
                            sumMoney=sumMoney.add(new BigDecimal(map2.get("data").toString()));
                        }
                    }
                    eleMoneyDaHua=sumMoney.multiply(price).divide(EleFee,2);
                }else{
                    return result.putFailed("第三方服务器繁忙");
                }
            }
            eleMoneySum=eleMoneyBee.add(eleMoneyDaHua);
            resultMap.put("eleMoneySum",eleMoneySum);
        }else{
            //zc修改
            resultMap.put("eleMoneySum",eleMoneySum);
            //return result.putFailed("服务器繁忙");


        }
        return result.put(resultMap);
    }

    @Override
    public JsonResult getTenRoom(Map<String, Object> params) {

        JsonResult result = new JsonResult();
        return result.put(hoHpiMapper.getTenRoom(params));


    }
}
